import { useState } from "react"

// 定义设备状态接口，与后端 DeviceStateBase 对应
interface DeviceStateBase {
  isOnline: boolean
  isRun: boolean
  isRs: boolean
  isPause: boolean
}

// 定义完整的设备状态接口，与后端 DeviceState.to_dict() 返回的数据对应
export interface DeviceStateData {
  cutPlcState: DeviceStateBase
  cameraGroupState: boolean[]
  workStopState: boolean
}

export default function deviceModel() {
  // 初始化设备状态
  const initState: DeviceStateData = {
    cutPlcState: {
      isOnline: false,
      isRun: false,
      isRs: false,
      isPause: false
    },

    cameraGroupState: [false, false, false],
    workStopState: true
  }

  const [deviceState, setDeviceState] = useState<DeviceStateData>(initState)
  const [workStopState, setWorkStopState] = useState<boolean>(true)

  return {
    ...deviceState,
    workStopState,
    updateDeviceState: (newState: DeviceStateData) => setDeviceState(newState),
    updateWorkStopState: (newState: boolean) => setWorkStopState(newState)
  }
}
